package com.kingdee.eas.scm.sm.pur.client;

import java.util.Iterator;
import java.util.Set;
import com.kingdee.bos.dao.query.IQueryExecutor;
import com.kingdee.bos.dao.query.QueryExecutorFactory;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.jky.helper.JKYHelper;

public class PurRequestListUICTEx extends PurRequestListUI {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3697806834682175654L;

	public PurRequestListUICTEx() throws Exception {
		super();

	}
	@Override
	protected boolean initDefaultFilter() {
		if (getUIContext().get("nextID") != null) {
			getUIContext().put(getMainBizOrgType(), SysContext.getSysContext().getCurrentFIUnit());
			return false;
		}else{
			return super.initDefaultFilter();
		}
		

	}
	@Override
	protected IQueryExecutor getQueryExecutor(IMetaDataPK queryPK,
			EntityViewInfo viewInfo) {
		if (getUIContext().get("nextID") != null) {
			IQueryExecutor exec = null;
			FilterInfo filterInfo = new FilterInfo();
			Set setID = (Set) getUIContext().get("nextID");
			String projectID = null;
			Iterator it = setID.iterator();
			while (it.hasNext()) {
				projectID = (String) it.next();
				break;
			}
			if (projectID != null) {
				try {
					Set sets = JKYHelper.getPojectNextBillIDS(
							"T_SM_PurRequest", "CFDefineProjectID", "'"
									+ projectID + "'");
					filterInfo.getFilterItems()
							.add(
									new FilterItemInfo("id", sets,
											CompareType.INCLUDE));
					viewInfo = new EntityViewInfo();
					viewInfo.setFilter(filterInfo);
					exec = QueryExecutorFactory.getRemoteInstance(queryPK);
					exec.setObjectView(viewInfo);
				} catch (Exception e) {

					e.printStackTrace();
				}
			}
			return exec;
		} else {
			return super.getQueryExecutor(queryPK, viewInfo);
		}
	}
	@Override
	protected boolean isIgnoreCUFilter() {
		if (getUIContext().get("nextID") != null) {
			return true;
		} else {
			return super.isIgnoreCUFilter();
		}
	}
}